<template>
  <div class="mebase">
    <div class="mebase-img">
      <img :src="user.avatar" alt="" />
    </div>
    <div class="outcontainer" ref="containerDom">
      <svg width="700" height="250" class="text">
        <defs>
          <linearGradient id="geekColor" gradientTransform="rotate(90)">
            <stop offset="0%" stop-color="#000"></stop>
            <!-- //渐变动画 -->
            <animate
              attributeName="stop-color"
              values="#91bd3a;#12cad6;#91bd3a"
              dur="10s"
              begin="3s"
              repeatCount="indefinite"
            ></animate>
            <stop offset="100%" stop-color="#12cad6"></stop>
          </linearGradient>
        </defs>
        <text style="text-anchor: middle" class="logo_text" :x="x" y="100">
          {{ user.username }}
        </text>
        <text style="text-anchor: middle" class="logo_text" :x="x" y="150">
          {{ user.realname }}
        </text>
      </svg>
    </div>
    <div class="email">
      <span>{{ user.email || "" }}</span>
    </div>
    <span @click="Logout()" class="logout">退出登陆</span>
  </div>
</template>

<script setup lang="ts">
import { computed, ref } from "vue";
import { useStore } from "vuex";
import { useRouter } from "vue-router";
const router = useRouter();
const store = useStore();
const user = computed(() => store.getters.user);
const containerDom = ref<HTMLDivElement | null>(null);
const x = computed(() => {
  const w = containerDom.value?.getBoundingClientRect().width;
  return w && w / 2;
});
const Logout = () => {
  localStorage.removeItem("LoginToken");
  store.dispatch("setUser", {
    username: "",
    avatar: "",
    status: 0,
    id: "",
    realname: "",
  });
  store.dispatch("setToken", false);
  router.replace("/index-h5");
};
</script>

<style lang="scss" scoped>
.mebase {
  position: absolute;
  left: 0;
  right: 0;
  left: 0;
  top: 0;
  bottom: 0;
  margin: auto;
  width: 100%;
  height: 70%;
  text-align: center;
  &-img {
    text-align: center;
    img {
      width: 100px;
      height: 100px;
      border-radius: 50%;
    }
  }
  .email {
    margin-bottom: 20px;
    span {
      font-size: 18px;
      color: #3478c6;
    }
  }
  .logout {
    color: #ea534f;
  }
}
.outcontainer {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 200px;
}

.logo_text {
  font-size: 26px;
  fill: none;
  stroke: url(#geekColor);
  stroke-width: 1;
  stroke-dasharray: 10 280;
  stroke-dashoffset: 10;
  animation: drawing 4.3s linear 0s forwards;
}

p {
  font-weight: 200;
  font-size: 20px;
  line-height: 28px;

  button {
    background-color: transparent;
    border: 1px solid rgba(0, 0, 0, 0.5);
    border-radius: 5px;
    margin-left: 10px;
  }
}
@keyframes drawing {
  to {
    stroke-dasharray: 280;
    stroke-dashoffset: 0;
  }
}
</style>
